package cn.lingyangwl.agile.msg.push.config.wxjava;

import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import cn.lingyangwl.framework.core.utils.spring.SpringUtils;
import com.binarywang.spring.starter.wxjava.miniapp.config.storage.AbstractWxMaConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author shenguangyang
 */
public class WxMaInRedisTemplateConfigStorageConfiguration extends AbstractWxMaConfigStorageConfiguration {
    private final WxMaProperties properties;

    public WxMaConfig wxMaConfig() {
        WxMaRedisBetterConfigImpl config = this.getWxMaInRedisTemplateConfigStorage();
        return this.config(config, this.properties);
    }
    private WxMaRedisBetterConfigImpl getWxMaInRedisTemplateConfigStorage() {
        StringRedisTemplate redisTemplate = SpringUtils.getBean(StringRedisTemplate.class);
        WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
        return new WxMaRedisBetterConfigImpl(redisOps, this.properties.getConfigStorage().getKeyPrefix());
    }

    public WxMaInRedisTemplateConfigStorageConfiguration(WxMaProperties properties) {
        this.properties = properties;
    }
}
